package com.android.semita;

import java.util.List;

import com.android.semita.model.Invoice;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class InvoiceAdapter extends ArrayAdapter<Invoice> {
	int resource;

	public InvoiceAdapter(Context context, int resource, List<Invoice> items) {
		super(context, resource, items);
		this.resource = resource;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout newView;
		Invoice classInstance = getItem(position);

		String invoiceNo = classInstance.getInvoiceNo();
		String customerName = classInstance.getCustomerName();
		//String invoiceAmount = Float.toString(classInstance.getInvoiceAmount());
		String invoiceAmount = classInstance.getInvoiceAmountNumberFormat();
		
		
		// TODO Retrieve values to display from the classInstance variable.
		// Inflate a new view if this is not an update.
		if (convertView == null) {
			newView = new LinearLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
					inflater);
			vi.inflate(resource, newView, true);
		} else {
			newView = (LinearLayout) convertView;
		}

		TextView tvInvoiceNo = (TextView) newView.findViewById(R.id.tvInvoiceNo);
		TextView tvCustomerName = (TextView) newView.findViewById(R.id.tvCustomerName);
		TextView tvInvoiceAmount = (TextView) newView.findViewById(R.id.tvInvoiceAmount);

		tvInvoiceNo.setText(invoiceNo);
		tvCustomerName.setText(customerName);
		tvInvoiceAmount.setText(invoiceAmount);

		return newView;
	}
}
